<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/layui-2.4.2/src/css/layui.css">
    <script type="text/javascript" src="/jquery/jquery-1.8.0.min.js"></script>
    <script type="text/javascript" src="/layui-2.4.2/src/layui.js"></script>
</head>
<body>
<div>
    <div class="layui-row">
        <div class="layui-form">
            <div class="layui-form-item">
                <label class="layui-form-label">手机号:</label>
                <div class="layui-input-inline">
                    <input type="text" id="user_phone_input" name="user_phone_input" lay-verify="required|phone"
                           placeholder="请输入手机号"
                           autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">姓名:</label>
                <div class="layui-input-inline">
                    <input type="text" id="user_name_input" name="user_name_input" required lay-verify="required"
                           placeholder="请输入姓名"
                           autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">身份证号:</label>
                <div class="layui-input-inline">
                    <input type="text" id="user_idno_input" name="user_idno_input" lay-verify="identity"
                           placeholder="请输入身份证号"
                           autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">支付密码:</label>
                <div class="layui-input-inline">
                    <input type="text" id="user_pwd_input" name="user_pwd_input" required lay-verify="required"
                           placeholder="请输入支付密码"
                           autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn" id="search">身份证号搜索</button>
                <button class="layui-btn" id="auth">实名认证</button>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <table id="user_list_view" lay-filter="user_filter">

        </table>
    </div>
</div>
</body>

<!--表格toobar模板-->
<script type="text/html" id="toolOper">
    <a class="layui-btn layui-btn-xs" lay-event="delAuth">删除</a>
</script>


<script>
    layui.use(['element', 'table', 'upload', 'laytpl', 'form'], function () {
        var table = layui.table;
        $("#search").on('click', function () {
            table.render({
                elem: '#user_list_view',
                // url: '/authAgain/queryList',
                page: true,
                // limit: 10,
                // limits: [10, 20, 50, 100],
                cols: [
                    [
                        {field: 'realName', title: '真实姓名', width: 120},
                        {field: 'idCard', title: '身份证号'},
                        {field: 'createTime', title: '创建时间', width: 120},
                        {field: 'right', align: 'center', toolbar: '#toolOper'}
                    ]
                ],
                response: {
                    status: 'errorCode',
                    countName: 'total',
                    dataName: 'data'
                }
            });
            table.reload('user_list_view', {
                url: '/authAgain/queryList',
                where: {
                    idCard: $('#user_idno_input').val()
                }
            });
        });

        $("#auth").on('click', function () {
            $.ajax({
                type: 'post',
                data: {
                    "name": $('#user_name_input').val(),
                    "mobile": $('#user_phone_input').val(),
                    "idNo": $('#user_idno_input').val(),
                    "pwd": $('#user_pwd_input').val()
                },
                url: '/authAgain/auth',
                cache: false,
                dataType: 'json',
                success: function (result) {
                    if (result.success == true) {
                        alert('实名成功！');
                    } else {
                        alert(result.msg);
                    }
                }
            });
            table.reload('user_list_view', {
                url: '/authAgain/queryList',
                where: {
                    idCard: $('#user_idno_input').val(),
                }
            });
        });

        table.on('tool(user_filter)',function(obj){
            var data=obj.data;
            var layEvent=obj.event;
            //删除实名信息
            if(layEvent==='delAuth'){
                if(window.confirm('请确认是否将'+data.idCard+'身份信息删除')){
                    $.ajax({
                        type:'post',
                        data:{CardId:data.idCard},
                        url:'/authAgain/delByCardId',
                        cache:false,
                        success:function(data){
                            if(data.success==true){
                                alert("身份信息删除成功");
                            }else {
                                alert(data.mes);
                            }
                        }
                    })
                }
            }
            table.reload('user_list_view', {
                url: '/authAgain/queryList',
                where: {
                    idCard: $('#user_idno_input').val(),
                }
            });

        });


    });
</script>
</html>